package com.feihong.txgw.ui.activity.kuandai;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.TypedValue;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.RelativeLayout;

import com.feihong.txgw.R;
import com.feihong.txgw.http.Host;
import com.feihong.txgw.message.LoginMessage;
import com.feihong.txgw.ui.activity.base.BaseActivity;
import com.feihong.txgw.view.WebView4Scroll;
import com.just.agentweb.AgentWeb;

import butterknife.BindView;

import static android.view.View.OVER_SCROLL_NEVER;

/**
 * @author wangziheng
 * @name txgw_app
 * @class name：com.feihong.txgw.ui.activity.kuandai
 * @class describe:  宽带预约
 * @time 2018/4/3 16:03
 * @change
 * @chang time
 * @class describe
 */
public class KuanDaiYuYueActivity extends BaseActivity {
    private AgentWeb mAgentWeb;
    @BindView(R.id.kuandai_swiprefrshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
    @BindView(R.id.kuandaiWebviewFrame) RelativeLayout mWebviewFrame;
    private String mUrl = Host.HTTP_HOME + "Yuyue/Broadband/index";

    @Override
    public void setTheme() {

    }

    @Override
    public int setLayoutID() {
        return R.layout.activity_kuandai_yuyue_layout;
    }

    @Override
    public void initView(Bundle savedInstanceState) {

        setPageTitle("宽带预约");
        setBackButtonFinish();
    }

    @Override
    public void bindData() {

        mSwipeRefreshLayout.setProgressBackgroundColorSchemeResource(android.R.color.white);
        mSwipeRefreshLayout.setColorSchemeResources(R.color.appRed,
                android.R.color.holo_red_light, android.R.color.holo_orange_light,
                android.R.color.holo_green_light);
        mSwipeRefreshLayout.setProgressViewOffset(false, 0, (int) TypedValue
                .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 24, getResources()
                        .getDisplayMetrics()));
        WebView4Scroll webView4Scroll = new WebView4Scroll(getActivity(), mSwipeRefreshLayout);
        webView4Scroll.setVerticalScrollBarEnabled(false);
        webView4Scroll.setOverScrollMode(OVER_SCROLL_NEVER);
        mAgentWeb = AgentWeb.with(this)
                .setAgentWebParent(mWebviewFrame, new RelativeLayout.LayoutParams(-1, -1))
                .useDefaultIndicator()
                .setWebChromeClient(null).setWebView(webView4Scroll)
                .setWebViewClient(mWebViewClient)
                .setMainFrameErrorView(R.layout.agentweb_errorlayout, R.id.agentweb_re_query_data_layout)
                .createAgentWeb()
                .ready()
                .go(mUrl);
        mAgentWeb.getAgentWebSettings().getWebSettings().setGeolocationEnabled(false);

    }


    private WebViewClient mWebViewClient = new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return true;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            mSwipeRefreshLayout.setRefreshing(false);
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    };
    private WebChromeClient mWebChromeClient = new WebChromeClient() {


    };
    @Override
    public void onUserLogin(LoginMessage loginMessage) {

    }
}
